﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATA.Business;
using ATA.Entities;
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;

using System.Configuration;

namespace ATA.Winforms.Admin
{
    public partial class HoiVien : Form
    {
        #region "Variables"
        KhachHang _UpdatedKhachHang;
        #endregion

        #region "Control Events"
        public HoiVien()
        {
            try
            {
                InitializeComponent();

                Infragistics.Win.UltraWinEditors.DropDownEditorButton drpbtnKhachHang = new Infragistics.Win.UltraWinEditors.DropDownEditorButton();
                drpbtnKhachHang.Control = ultraGrid1;
                this.txtTenKhachHang.ButtonsRight.Add(drpbtnKhachHang);

                Infragistics.Win.UltraWinEditors.DropDownEditorButton drpbtnDaiLy = new Infragistics.Win.UltraWinEditors.DropDownEditorButton();
                drpbtnDaiLy.Control = grdDaiLy;
                this.txtDaiLy.ButtonsRight.Add(drpbtnDaiLy);

                RefreshForm();
            }
            catch (Exception ex)
            {

            }
        }

        //private void btnSave_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string Error = IsError();
        //        if (!string.IsNullOrEmpty(IsError()))
        //        {
        //            lblMessage.Text = Error;
        //            return;
        //        }
        //        KhachHangService ks = new KhachHangService();
        //        KhachHang _KhachHang;
        //        //if (_UpdatedKhachHang == null)
        //        //{
        //            _KhachHang = new KhachHang();
        //            _KhachHang = setKhachHangData(_KhachHang);
        //            ks.Insert(_KhachHang);
        //            lblMessage.Text = "Thêm Mới thành công!";
        //            RefreshForm();
        //        //}                
        //    }
        //    catch (Exception ex)
        //    {
        //        lblMessage.Text = "Chương trình không thể thêm mới!";
        //    }
        //}

        private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
        {
            
        }

        //private void btnUpdate_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string Error = IsError();
        //        if (!string.IsNullOrEmpty(IsError()))
        //        {
        //            lblMessage.Text = Error;
        //            return;
        //        }
        //        if (_UpdatedKhachHang != null)
        //        {
        //            KhachHang _KhachHang = _UpdatedKhachHang;
        //            _KhachHang = setKhachHangData(_KhachHang);
        //            (new KhachHangService()).Update(_KhachHang);
        //            _UpdatedKhachHang = null;
        //            lblMessage.Text = "Cập Nhật thành công!";
        //            RefreshForm();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        lblMessage.Text = "Chương trình không thể cập nhật";
        //    }                
        //}

        //private void btnDelete_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (_UpdatedKhachHang != null)
        //        {
        //            (new KhachHangService()).Delete(_UpdatedKhachHang);
        //            _UpdatedKhachHang = null;
        //            lblMessage.Text = "Xóa thành công!";
        //            RefreshForm();
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        lblMessage.Text = "Chương trình không thể xóa!";
        //    }
        //}

        //private void btnRefresh_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        RefreshForm();
        //    }
        //    catch (Exception ex)
        //    {


        //    }
        //}

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Appearance.FontData.SizeInPoints = 8;
            //ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextCell;
            //ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.Vertical;

            ////ultraGrid1.DisplayLayout.GroupByBox.Style = GroupByBoxStyle.Compact;
            ////ultraGrid1.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.InsetSoft;
            ////ultraGrid1.DisplayLayout.GroupByBox.ButtonBorderStyle = UIElementBorderStyle.RaisedSoft;
            ////ultraGrid1.DisplayLayout.GroupByBox.BandLabelBorderStyle = UIElementBorderStyle.Solid;
            ////ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorStyle = UIElementBorderStyle.Dotted;
            ////ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorColor = Color.Maroon;

            //ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free;
            ////ultraGrid1.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ColumnChooserButton;
            //ultraGrid1.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
            //ultraGrid1.DisplayLayout.Override.FixedCellSeparatorColor = Color.Red;
            //ultraGrid1.DisplayLayout.Override.FixedHeaderIndicator = FixedHeaderIndicator.Button;
            ////ultraGrid1.DisplayLayout.Override.GroupByRowInitialExpansionState = GroupByRowInitialExpansionState.Expanded;
            ////ultraGrid1.DisplayLayout.Override.GroupByColumnsHidden = DefaultableBoolean.False;
            //ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
            ////ultraGrid1.DisplayLayout.Override.AllowRowSummaries = AllowRowSummaries.True;
            //ultraGrid1.DisplayLayout.Override.FixedRowSortOrder = FixedRowSortOrder.FixOrder;
            //ultraGrid1.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
            //ultraGrid1.DisplayLayout.Override.HeaderPlacement = HeaderPlacement.FixedOnTop;
            //ultraGrid1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True;
            //ultraGrid1.DisplayLayout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            ////ultraGrid1.DisplayLayout.Override.AllowGroupBy = DefaultableBoolean.False;
            ////ultraGrid1.DisplayLayout.Override.GroupByColumnsHidden = DefaultableBoolean.True;
            //ultraGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;

            //ultraGrid1.DisplayLayout.UseFixedHeaders = true;
            
            //foreach (UltraGridBand b in ultraGrid1.DisplayLayout.Bands)
            //{
            //    foreach (UltraGridColumn c in b.Columns)
            //    {
            //        if ((c.Key.ToString().Equals("MaKh")) ||
            //            (c.Key.ToString().Equals("LoaiKh")) || (c.Key.ToString().Equals("SoHoaDon")) ||
            //            (c.Key.ToString().Equals("NgayLayHang")) || (c.Key.ToString().Equals("DoanhSo")) || (c.Key.ToString().Equals("GhiChu")) ||
            //            (c.Key.ToString().Equals("NgayDangKy")))
            //        {
            //            c.Hidden = true;
            //            c.ExcludeFromColumnChooser = ExcludeFromColumnChooser.True;
            //        }
            //        else
            //            c.Hidden = false;

            //        if (c.Key.ToString().Equals("TenKh"))
            //            c.Header.Caption = "Tên Khách Hàng";
            //        if (c.Key.ToString().Equals("GioiTinh"))
            //            c.Header.Caption = "Giới Tính";
            //        if (c.Key.ToString().Equals("NgaySinh"))
            //        {
            //            c.Header.Caption = "Ngày Sinh";
            //            c.Format = "dd/MM/yyyy";
            //            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
            //        }
            //        if (c.Key.ToString().Equals("Cmnd"))
            //            c.Header.Caption = "CMND";
            //        if (c.Key.ToString().Equals("NgayCap"))
            //        {
            //            c.Header.Caption = "Ngày Cấp";
            //            c.Format = "dd/MM/yyyy";
            //            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
            //        }
            //        if (c.Key.ToString().Equals("NoiCap"))
            //            c.Header.Caption = "Nơi Cấp";
            //        if (c.Key.ToString().Equals("SoDtDk"))
            //            c.Header.Caption = "Số Điện Thoại";
            //        if (c.Key.ToString().Equals("SoDtCty"))
            //            c.Header.Caption = "Số Điện Thoại Công Ty";
            //        if (c.Key.ToString().Equals("Fax"))
            //            c.Header.Caption = "Fax";
            //        if (c.Key.ToString().Equals("SoGpdkkd"))
            //            c.Header.Caption = "Số GPDKKD";
            //        if (c.Key.ToString().Equals("DiaChiTt"))
            //            c.Header.Caption = "Địa Chỉ";
            //        if (c.Key.ToString().Equals("HoKhauTt"))
            //            c.Header.Caption = "Hộ Khẩu";
            //        if (c.Key.ToString().Equals("LoaiHoiVien"))
            //            c.Header.Caption = "Loại Hội Viên";
            //        if (c.Key.ToString().Equals("MaSoHv"))
            //            c.Header.Caption = "Mã Số Hội Viên";
            //        if (c.Key.ToString().Equals("DiaChiCty"))
            //            c.Header.Caption = "Địa Chỉ Công Ty";
            //        if (c.DataType.Name == "DateTime")
            //        {
            //            c.Format = "dd/MM/yyyy";
            //            c.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Date;
            //        }
            //    }
            //}
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                string Error = IsError();
                if (!string.IsNullOrEmpty(IsError()))
                {
                    MessageBox.Show(Error);
                    return;
                }
                KhachHangService ks = new KhachHangService();
                KhachHang _KhachHang;
                //if (_UpdatedKhachHang == null)
                //{
                _KhachHang = new KhachHang();
                _KhachHang = setKhachHangData(_KhachHang);
                ks.Insert(_KhachHang);
                //lblMessage.Text = "Thêm Mới thành công!";
                MessageBox.Show(this, "Cập nhật thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                RefreshForm();
                //}                
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Chương trình không thể thêm mới!";
            }
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                string Error = IsError();
                if (!string.IsNullOrEmpty(IsError()))
                {
                    MessageBox.Show(Error);
                    return;
                }
                if (_UpdatedKhachHang != null)
                {
                    KhachHang _KhachHang = _UpdatedKhachHang;
                    _KhachHang = setKhachHangData(_KhachHang);
                    (new KhachHangService()).Update(_KhachHang);
                    _UpdatedKhachHang = null;
                    //lblMessage.Text = "Cập Nhật thành công!";
                    MessageBox.Show(this, "Cập nhật thông tin thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RefreshForm();
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Chương trình không thể cập nhật";
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                if (_UpdatedKhachHang != null)
                {
                    (new KhachHangService()).Delete(_UpdatedKhachHang);
                    _UpdatedKhachHang = null;
                    lblMessage.Text = "Xóa thành công!";
                    RefreshForm();
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Chương trình không thể xóa!";
            }
        }

        private void btnLamTuoi_Click(object sender, EventArgs e)
        {
            try
            {
                RefreshForm();
            }
            catch (Exception ex)
            {


            }
        }

        #endregion

        #region "Custom Methods"
        private string IsError()
        {
            string Error = string.Empty;
            if (txtTenKhachHang.Text == string.Empty)
                Error = string.Format("Yêu cầu nhập tên khách hàng!{0}", System.Environment.NewLine);
            if (drpNgaySinh.Value == null)
                Error = string.Format("{0}Yêu cầu nhập ngày sinh!{1}", Error, System.Environment.NewLine);
            if (txtDiaChiTamTru.Text == string.Empty)
                Error = string.Format("{0}Yêu cầu nhập địa chỉ tạm trú!{1}", Error, System.Environment.NewLine);
            if (txtHoKhauThuongTru.Text == string.Empty)
                Error = string.Format("{0}Yêu cầu nhập nơi đăng ký hộ khẩu thường trú!{1}", Error, System.Environment.NewLine);
            if (txtCMT.Value == null)
                Error = string.Format("{0}Yêu cầu nhập số chứng minh thư!{1}", Error, System.Environment.NewLine);
            if (drpNgayCapCMT.Value == null)
                Error = string.Format("{0}Yêu cầu nhập ngày cấp chứng minh thư!{1}", Error, System.Environment.NewLine);
            if (txtNoiCap.Text == string.Empty)
                Error = string.Format("{0}Yêu cầu nhập nơi cấp chứng minh thư!{1}", Error, System.Environment.NewLine);
            if (txtSoDienThoai.Text == string.Empty)
                Error = string.Format("{0}Yêu cầu nhập số điện thoại!{1}", Error, System.Environment.NewLine);
            if (grdDaiLy.ActiveRow.Index < 0)
                Error = string.Format("{0}Yêu cầu nhập đại lý!{1}", Error, System.Environment.NewLine);
            if (txtMaSoHoiVien.Text.Trim() == string.Empty)
                Error = string.Format("{0}Yêu cầu nhập mã số hội viên!{1}", Error, System.Environment.NewLine);
            return Error;
        }
        private void RefreshForm()
        {
            setDropDownToTxtTenKhachHang();
            _UpdatedKhachHang = null;
            txtCustomerName.Value = null;
            txtCustomerName.Text = string.Empty;
            drpGioiTinh.SelectedIndex = 0;
            drpNgaySinh.Text = string.Empty;
            txtDiaChiCongTy.Value = null;
            txtDiaChiTamTru.Value = null;
            txtFax.Value = null;
            txtHoKhauThuongTru.Value = null;
            txtMaSoHoiVien.Value = null;
            drpNgayCapCMT.Text = string.Empty;
            txtNoiCap.Value = null;
            txtSoDienThoai.Value = null;
            txtSoGPDKKD.Value = null;
            txtCMT.Value = null;
            drpDaiLy.SelectedRow  = null;
            txtSoDienThoaiCongTy.Value = null;
            //Utility.setEmptyTextToTextBoxes(this);
            //lblMessage.Text = string.Empty;
        }

        private KhachHang setKhachHangData(KhachHang _KhachHang)
        {
            try
            {
                if (_KhachHang.KhachHangId == null || _KhachHang.KhachHangId == Guid.Empty)
                {
                    _KhachHang.KhachHangId = Guid.NewGuid();
                }
                //_KhachHang.ParentId = (Guid)drpDaiLy.SelectedRow.Cells["AccountingObjectID"].Value;
                _KhachHang.ParentId = (Guid)grdDaiLy.ActiveRow.Cells["AccountingObjectID"].Value;
                _KhachHang.DiaChiCty = txtDiaChiCongTy.Text;
                _KhachHang.DiaChiTt = txtDiaChiTamTru.Text;
                _KhachHang.Fax = txtFax.Text;
                _KhachHang.GioiTinh = (string)drpGioiTinh.SelectedItem.DataValue;
                _KhachHang.HoKhauTt = txtHoKhauThuongTru.Text;
                _KhachHang.LoaiKh = (short)rdoLoaiTheHoiVien.CheckedItem.DataValue;
                _KhachHang.MaKh = txtMaSoHoiVien.Text;
                _KhachHang.MaSoHv = txtMaSoHoiVien.Text;
                _KhachHang.NgayCap = Utility.getDateTime(drpNgayCapCMT.Value);
                _KhachHang.NgaySinh = Utility.getDateTime(drpNgaySinh.Value);
                _KhachHang.NoiCap = txtNoiCap.Text;
                _KhachHang.SoDtCty = txtSoDienThoaiCongTy.Text;
                _KhachHang.SoDtDk = txtSoDienThoai.Text;
                _KhachHang.SoGpdkkd = txtSoGPDKKD.Text;
                _KhachHang.TenKh = txtTenKhachHang.Text;
                _KhachHang.Cmnd = txtCMT.Value.ToString();
                _KhachHang.BranchId = (Guid)cboBranch.Value;

                return _KhachHang;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        private void setDropDownToTxtTenKhachHang()
        {
            TList<KhachHang> KhachHangList = (new KhachHangService()).GetAll();
            if (KhachHangList != null)
            {
                if (KhachHangList.Count > 0)
                {
                    KhachHangList.AddNew();
                    ultraGrid1.DataSource = KhachHangList;
                    ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Activated = true;
                }
            }
        }

        private void LoadGridDaiLy()
        {
            //drpDaiLy.DisplayMember = "AccountingObjectCode";
            //drpDaiLy.ValueMember = "AccountingObjectID";
            grdDaiLy.DataSource = Globals.gv_lsCustomers;
            grdDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectID"].Hidden = true;
            grdDaiLy.DisplayLayout.Bands[0].Columns["ParentAccountingObjectId"].Hidden = true;
            grdDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Header.Caption = "Mã KH";
            grdDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Width = 80;
            grdDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Header.Caption = "Tên KH";
            grdDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Width = 250;

        }

        private void loadDrpDaiLy()
        {
            //TList<KhachHang> DaiLyList = (new KhachHangService()).Find("ISACTIVE = TRUE");

            //if (DaiLyList != null)
            //{
            //    if (DaiLyList.Count > 0)
            //    {
            //        drpDaiLy.DataSource = DaiLyList;
            //        drpDaiLy.DisplayMember = "TenDaiLy";
            //        drpDaiLy.ValueMember = "DaiLyID";
            //        drpDaiLy.SelectedIndex = 0;
            //    }
            //}

            drpDaiLy.DisplayMember = "AccountingObjectCode";
            drpDaiLy.ValueMember = "AccountingObjectID";
            drpDaiLy.DataSource = Globals.gv_lsCustomers;
            drpDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectID"].Hidden = true;
            drpDaiLy.DisplayLayout.Bands[0].Columns["ParentAccountingObjectId"].Hidden = true;
            drpDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Header.Caption = "Mã KH";
            drpDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectCode"].Width = 80;
            drpDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Header.Caption = "Tên KH";
            drpDaiLy.DisplayLayout.Bands[0].Columns["AccountingObjectName"].Width = 250;
            drpDaiLy.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;

        }

        private void LoadBranch()
        {
            #region Load chi nhanh
            ATA.Data.MisaDAL.DAL dal = new ATA.Data.MisaDAL.DAL(ConfigurationManager.ConnectionStrings["misaConnectionString"].ConnectionString, ConfigurationManager.ConnectionStrings["netTiersConnectionString"].ConnectionString);
            DataSet v_dsBranches;

            if (Globals.gv_bIsGlobalBranch)
            {
                v_dsBranches = dal.GetAllActiveBranchs();
                cboBranch.DataSource = v_dsBranches;
                cboBranch.DataMember = v_dsBranches.Tables[0].TableName;
                //cboBranch.SelectedItem = cboBranch.Items.IndexOf(cboBranch.Items.ValueList.ValueListItems.);
                cboBranch.Enabled = true;
            }
            else
            {
                v_dsBranches = dal.GetActiveBranchsByID(Globals.gv_strBranchID);
                cboBranch.DataSource = v_dsBranches;
                cboBranch.DataMember = v_dsBranches.Tables[0].TableName;
                cboBranch.SelectedIndex = 0;
                cboBranch.Enabled = false;
            }
            
            cboBranch.DisplayMember = "BranchName";
            cboBranch.ValueMember = "BranchID";
            cboBranch.DataBind();
            #endregion

        }
        #endregion

        private void drpDaiLy_ValueChanged(object sender, EventArgs e)
        {
            if (drpDaiLy.SelectedRow == null)
                return;

            txtCustomerName.Text = drpDaiLy.SelectedRow.Cells["AccountingObjectName"].Value.ToString();
        }

        private void HoiVien_Load(object sender, EventArgs e)
        {
            LoadBranch();
            loadDrpDaiLy();
            LoadGridDaiLy();
        }

        private void txtTenKhachHang_AfterEditorButtonCloseUp(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            try
            {
                if (this.ultraGrid1.ActiveRow.Index > -1)
                {
                    KhachHang _KhachHang = (new KhachHangService()).GetByKhachHangId((Guid)this.ultraGrid1.ActiveRow.Cells["KhachHangID"].Value);
                    if (_KhachHang != null)
                    {
                        _UpdatedKhachHang = _KhachHang;
                        this.txtCMT.Value = _KhachHang.Cmnd;
                        this.txtDiaChiCongTy.Text = _KhachHang.DiaChiCty;
                        this.txtDiaChiTamTru.Text = _KhachHang.DiaChiTt;
                        this.txtFax.Text = _KhachHang.Fax;
                        this.txtHoKhauThuongTru.Text = _KhachHang.HoKhauTt;
                        //this.txtMaSoHoiVien.Text = _KhachHang.MaKh;
                        this.txtMaSoHoiVien.Text = _KhachHang.MaSoHv;
                        this.txtNoiCap.Text = _KhachHang.NoiCap;
                        this.txtSoDienThoai.Text = _KhachHang.SoDtDk;
                        this.txtSoDienThoaiCongTy.Text = _KhachHang.SoDtCty;
                        this.txtSoGPDKKD.Text = _KhachHang.SoGpdkkd;
                        this.txtTenKhachHang.Text = _KhachHang.TenKh;
                        //this.drpDaiLy.Value = _KhachHang.ParentId;

                        this.drpGioiTinh.SelectedIndex = this.drpGioiTinh.Items.IndexOf((drpGioiTinh.Items.ValueList.FindByDataValue(_KhachHang.GioiTinh)));
                        this.drpNgayCapCMT.Value = _KhachHang.NgayCap;
                        this.drpNgaySinh.Value = _KhachHang.NgaySinh;
                        this.rdoLoaiTheHoiVien.CheckedIndex = rdoLoaiTheHoiVien.Items.IndexOf(rdoLoaiTheHoiVien.Items.ValueList.FindByDataValue(_KhachHang.LoaiKh));
                        cboBranch.Value = _KhachHang.BranchId.Value;
                    }
                }
            }
            catch (Exception)
            {


            }
        }

        private void ultraGrid1_DoubleClickRow(object sender, DoubleClickRowEventArgs e)
        {
            txtCustomerName.Focus();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void drpDaiLy_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            drpDaiLy.DisplayLayout.Bands[0].Columns["ParentAccountingObjectId"].Hidden = true;
        }

        private void grdDaiLy_DoubleClickRow(object sender, DoubleClickRowEventArgs e)
        {
            txtDaiLy.Focus();
        }

        private void txtDaiLy_AfterEditorButtonCloseUp(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            try
            {
                if (this.grdDaiLy.ActiveRow.Index > -1)
                {
                    txtDaiLy.Value = grdDaiLy.ActiveRow.Cells["AccountingObjectCode"].Value;
                    txtCustomerName.Value = grdDaiLy.ActiveRow.Cells["AccountingObjectName"].Value;
                }
            }
            catch (Exception)
            {


            }
        }


    }
}
